package com.diaohw.module.websocket.service.ws.handle;

import com.diaohw.module.websocket.obj.vo.MsgVO;
import com.diaohw.module.websocket.properties.RabbitMsgProcessProperties;
import com.diaohw.platform.common.util.JsonUtil;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import static com.diaohw.module.websocket.properties.WsMessageProperties.RABBIT_CONFIG;


@Service
@ConditionalOnProperty(RABBIT_CONFIG)
public class RabbitMQHandle {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @SneakyThrows
    public void execute(RabbitMsgProcessProperties config, MsgVO message) {
        Message msg = new Message(JsonUtil.toBytes(message));
        rabbitTemplate.send(config.getExchange(), config.getRoutingKey(), msg);
    }


}
